package com.kk.xhr.common.pojo;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 性别枚举类
 *
 * @author luokexiong
 * @version 1.0 2021/2/14
 * @since 1.0.0
 */
@Getter
@AllArgsConstructor
public enum GenderEnum {
    /** 女性 */
    FEMALE((byte) 0),
    /** 男性 */
    MALE((byte) 1);

    private final byte value;
    private static final Map<Byte, GenderEnum> map = Arrays.stream(GenderEnum.values())
        .collect(Collectors.toMap(GenderEnum::getValue, Function.identity()));

    public static GenderEnum from(Byte from) {
        if (null == from) {
            return null;
        }
        return map.getOrDefault(from, MALE);
    }
}
